﻿using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using System.Data;

namespace elr_tracking_bal
{
    [DataContractAttribute]
    public class INFORMATION_COLUMNS
    {
        [DataMemberAttribute(EmitDefaultValue = false)]
        public string COLUMN_NAME;
        [DataMemberAttribute(EmitDefaultValue = false)]
        public int CHARACTER_MAXIMUM_LENGTH;
        /// <summary>
        /// Método que obtiene la información de las columnas de tipo nvarchar
        /// </summary>
        /// <param name="NAME_TABLE"></param>
        /// <returns></returns>
        public static List<INFORMATION_COLUMNS> GetInformationColumns(string NAME_TABLE)
        {
            try
            {
                DataTable dt = elr_tracking_dal.SrvDB.ExecuteQuery("exec SP_INFORMATION_COLUMNS '" + NAME_TABLE + "'");
                if (dt.Rows.Count == 0)
                {
                    return null;
                }
                else
                {
                    List<INFORMATION_COLUMNS> list = dt.AsEnumerable().Select(
                        row => new elr_tracking_bal.INFORMATION_COLUMNS
                        {
                            COLUMN_NAME = String.IsNullOrEmpty(row.Field<string>(3)) ? "" : row.Field<string>(3),
                            CHARACTER_MAXIMUM_LENGTH = row.Field<int?>(8).GetValueOrDefault(),
                        }
                        ).ToList();
                    return list;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Constructor sin parámetros
        /// </summary>
        public INFORMATION_COLUMNS() { }
        /// <summary>
        /// Constructor con dos parámetros
        /// </summary>
        /// <param name="COLUMN_NAME"></param>
        /// <param name="CHARACTER_MAXIMUM_LENGTH"></param>
        public INFORMATION_COLUMNS(string COLUMN_NAME, int CHARACTER_MAXIMUM_LENGTH)
        {
            this.COLUMN_NAME = COLUMN_NAME;
            this.CHARACTER_MAXIMUM_LENGTH = CHARACTER_MAXIMUM_LENGTH;
        }
    }
}